package collection遍历方法;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class 迭代器 {
    public static void main(String[] args) {
        Collection<String> c = new ArrayList<>();
        c.add("Java");
        c.add("HTML");
        c.add("MySQL");
        c.add("Java");
        Iterator<String> it = c.iterator();
//        String ele1 = it.next();
//        String ele2 = it.next();
//        String ele3 = it.next();
//        String ele4 = it.next();
//        String ele5 = it.next();  出现此处无元素的错误
//        System.out.println(ele1);
        String ele;
        while(it.hasNext()){
            ele = it.next();
            System.out.println(ele);
        }
    }

}
